package vip.xiaonuo.app.modular.dynamic.controller.front;

import cn.hutool.core.util.ObjectUtil;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.app.modular.dynamic.param.front.ApiGetDynamicListParam;
import vip.xiaonuo.app.modular.dynamic.param.front.ApiSendDynamicParam;
import vip.xiaonuo.app.modular.dynamic.service.AppDynamicService;
import vip.xiaonuo.core.context.login.LoginContextHolder;
import vip.xiaonuo.core.pojo.login.BaseUserDetailService;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.core.pojo.response.SuccessResponseData;

import javax.annotation.Resource;

/**
 * <p>Title : 朋友圈</p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows11</p>
 *
 * @Author : zxw
 * @Date 2023/10/17 15:49
 */
@RestController
@RequestMapping("/api/dynamic")
public class ApiDynamicController {

    @Resource
    private AppDynamicService appDynamicService;


    /**
     * 发送朋友圈
     *
     * @param param
     * @return
     */
    @PostMapping("/sendDynamic")
    public ResponseData sendDynamic(@RequestBody ApiSendDynamicParam param) {
        BaseUserDetailService sysLoginUser = LoginContextHolder.me().getSysLoginUser();
        //获取用户id
        param.setUserId(sysLoginUser.getId());

        appDynamicService.sendDynamic(param);
        return new SuccessResponseData();
    }


    /**
     * 获取朋友圈
     */
    @GetMapping("/getDynamicList")
    public ResponseData getDynamicList(ApiGetDynamicListParam param) {

        Integer sex = LoginContextHolder.me().getSysLoginUser().getSex();
        //判断用户性别

        //判断 动态  还是  关注
        if (ObjectUtil.isNotEmpty(param.getType())){

            if (param.getType().equals(1)){

                return new SuccessResponseData(appDynamicService.getDynamicList(param));
            }

            if (param.getType().equals(2)){

                return new SuccessResponseData(appDynamicService.getDynamicList(param));
            }
        }
        return new SuccessResponseData();
    }






}
